home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / foo2qpdl-wrapper < prev    next >
Encoding:
Text File  |  2009-03-27  |  17.0 KB  |  704 lines

  1. #!/bin/sh
  2.  
  3. #* Copyright (C) 2003-2006  Rick Richardson
  4. #*
  5. #* This program is free software; you can redistribute it and/or modify
  6. #* it under the terms of the GNU General Public License as published by
  7. #* the Free Software Foundation; either version 2 of the License, or
  8. #* (at your option) any later version.
  9. #*
  10. #* This program is distributed in the hope that it will be useful,
  11. #* but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #* GNU General Public License for more details.
  14. #*
  15. #* You should have received a copy of the GNU General Public License
  16. #* along with this program; if not, write to the Free Software
  17. #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. #*
  19. #* Authors: Rick Richardson <rick.richardson@comcast.net>
  20.  
  21. VERSION='$Id: foo2qpdl-wrapper.in,v 1.37 2009/01/21 07:52:13 rick Exp $'
  22.  
  23. #
  24. # Printer Notes:
  25. #
  26. # Samsung CLP-300: -z0, ICM
  27. # Samsung CLP-315: -z2, ICM
  28. # Samsung CLP-600: -z1, CRD, need ICM for black text
  29. # Samsung CLP-610: -z2, CRD, need ICM for black text
  30. # Samsung CLX-2160: -z0, ICM
  31. # Samsung CLX-3160: -z0, ICM
  32. # Samsung CLX-3175: -z2, ICM
  33. # Xerox Phaser 6110: -z0, ICM
  34. # Xerox Phaser 6110MFP: -z0, ICM
  35. #
  36.  
  37. PROGNAME="$0"
  38. BASENAME=`basename $PROGNAME`
  39. PREFIX=/usr
  40. SHARE=$PREFIX/share/foo2qpdl
  41. PATH=$PATH:/sw/bin:/opt/local/bin
  42.  
  43. #
  44. #    Log the command line, for debugging and problem reports
  45. #
  46. if [ -x /usr/bin/logger ]; then
  47.     logger -t "$BASENAME" -p lpr.info -- "$BASENAME $@" </dev/null
  48. fi
  49.  
  50. usage() {
  51.     cat <<EOF
  52. Usage:
  53.     $BASENAME [options] [ps-file]
  54.  
  55.     Foomatic printer wrapper for the foo2qpdl printer driver.
  56.     This script reads a Postscript ps-file or standard input
  57.     and converts it to a Samsung QPDL stream (CLP-600).
  58.  
  59. Normal Options:
  60. -c                Print in color (else monochrome)
  61. -C colormode      Colormode [$COLORMODE]
  62.                     1=CRD
  63.                     10=ICM color profile (using -G *.icm file)
  64. -d duplex         Duplex code to send to printer [$DUPLEX]
  65.                     1=off, 2=longedge, 3=shortedge
  66. -m media          Media code to send to printer [$MEDIA]
  67.                     0=plain, 1=thick, 2=thin. 3=bond, 4=color, 5=card,
  68.                     6=labels, 7=envelope, 8=preprinted, 9=cotton,
  69.                     10=recycled, 11=transparency, 12=archive
  70. -p paper          Paper code [$PAPER]
  71.                     0=letter, 1=legal, A4=2, 3=executive, 6=env#10,
  72.                     7=envMonarch, 8=envC5, 9=envDL, 11=B5jis, 12=B5iso,
  73.                     16=A5, 17=A6, 23=envC6, 24=folio, 25=env6.75, 26=env#9,
  74.                     28=oficio
  75. -n copies         Number of copies [$COPIES]
  76. -r <xres>x<yres>  Set device resolution in pixels/inch [$RES]
  77. -s source         Source code to send to printer [$SOURCE]
  78.                     1=upper, 2=lower, 4=manual, 7=auto
  79.             Code numbers may vary with printer model.
  80. -t                Draft mode.  Every other pixel is white.
  81. -2/-3/-4/-6/-8/-10/-12/-14/-15/-16/-18
  82.                   Print with N-up (requires psutils)
  83. -o orient         For N-up: -op is portrait, -ol is landscape, -os is seascape.
  84.  
  85. Printer Tweaking Options:
  86. -u <xoff>x<yoff>  Set offset of upper left printable in pixels [varies]
  87. -l <xoff>x<yoff>  Set offset of lower right printable in pixels [varies]
  88. -L mask           Send logical clipping values from -u/-l in ZjStream [3]
  89.                   0=no, 1=Y, 2=X, 3=XY
  90. -P                Do not output START_PLANE codes.  May be needed by some
  91.                   monochrome-only printers.
  92. -X padlen         Add extra zero padding to the end of BID segments [16]
  93. -z model          Printer Model [$MODEL]
  94.                          0=CLP-300/CLX-2160/CLX-3160
  95.                          1=CLP-600
  96.                          2=CLP-315/CLP-610/CLX-3175
  97.  
  98. Color Tweaking Options:
  99. -g gsopts         Additional options to pass to Ghostscript, such as
  100.                   -dDITHERPPI=nnn, etc.  May appear more than once. []
  101. -G profile.icm    Convert profile.icm to a Postscript CRD using icc2ps and
  102.                   adjust colors using the setcolorrendering PS operator.
  103.                   $SHARE/icm/ will be searched for profile.icm.
  104. -I intent         Select profile intent from ICM file [$INTENT]
  105.                   0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute
  106. -G gamma-file.ps  Prepend gamma-file to the Postscript input to perform
  107.                   color correction using the setcolortransfer PS operator.
  108.  
  109. Debugging Options:
  110. -S plane          Output just a single color plane from a color print [all]
  111.                   1=Cyan, 2=Magenta, 3=Yellow, 4=Black
  112. -D lvl            Set Debug level [$DEBUG]
  113. -V                $VERSION
  114. EOF
  115.  
  116.     exit 1
  117. }
  118.  
  119. #
  120. #       Report an error and exit
  121. #
  122. error() {
  123.     echo "$BASENAME: $1" >&2
  124.     exit 1
  125. }
  126.  
  127. dbgcmd() {
  128.     if [ $DEBUG -ge 1 ]; then
  129.         echo "$@" >&2
  130.     fi
  131.     "$@"
  132. }
  133.  
  134. #
  135. #    N-up-ify the job.  Requires psnup from psutils package
  136. #
  137. nup() {
  138.     case "$NUP" in
  139.     [2368]|1[0458])
  140.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.3in -p$paper -q
  141.     ;;
  142.     [49]|1[26])
  143.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.5in -p$paper -q
  144.     ;;
  145.     *)
  146.     error "Illegal call to nup()."
  147.     ;;
  148.     esac
  149. }
  150.  
  151. #
  152. #       Process the options
  153. #
  154.  
  155. # Try to use a local copy of GhostScript 8.54, if available.  Otherwise,
  156. # fallback to whatever the Linux distro has installed (usually 7.07)
  157. #
  158. # N.B. := operator used here, when :- would be better, because "ash"
  159. # doesn't have :-
  160. if gs.foo -v >/dev/null 2>&1; then
  161.         GSBIN=${GSBIN:-gs.foo}
  162. else
  163.         GSBIN=${GSBIN:-gs}
  164. fi
  165.  
  166. CMDLINE="$*"
  167. DEBUG=0
  168. DUPLEX=1
  169. COLOR=
  170. COLORMODE=default
  171. MODEL=0
  172. QUALITY=1
  173. QUALITY=wts
  174. MEDIA=0
  175. COPIES=1
  176. test -r /etc/papersize && PAPER=$(cat /etc/papersize)
  177. test "$PAPER" || PAPER=0
  178. RES=1200x600
  179. SOURCE=1
  180. NUP=
  181. CLIP_UL=
  182. CLIP_LR=
  183. CLIP_LOG=
  184. BC=
  185. AIB=
  186. NOPLANES=
  187. COLOR2MONO=
  188. GAMMAFILE=default
  189. INTENT=0
  190. GSOPTS=
  191. EXTRAPAD=
  192. SAVETONER=
  193. NUP_ORIENT=
  194. GSDEV=-sDEVICE=pbmraw
  195. # What mode to use if the user wants us to pick the "best" mode
  196. case `$GSBIN --version` in
  197. 7*)    DEFAULTCOLORMODE=10
  198.     DEFAULTCOLORMODE=1
  199.     ;;
  200. 8.1*)
  201.     DEFAULTCOLORMODE=1
  202.     QUALITY=1
  203.     ;;
  204. *)    DEFAULTCOLORMODE=1
  205.     ;;
  206. esac
  207. while getopts "1:23456789o:b:cC:d:g:l:u:L:m:n:p:q:r:s:tz:ABS:D:G:I:PX:Vh?" opt
  208. do
  209.     case $opt in
  210.     b)    GSBIN="$OPTARG";;
  211.     c)    COLOR=-c;;
  212.     d)    DUPLEX="$OPTARG";;
  213.     g)    GSOPTS="$GSOPTS $OPTARG";;
  214.     m)    MEDIA="$OPTARG";;
  215.     n)    COPIES="$OPTARG";;
  216.     p)    PAPER="$OPTARG";;
  217.     q)    QUALITY="$OPTARG";;
  218.     r)    RES="$OPTARG";;
  219.     s)    SOURCE="$OPTARG";;
  220.     t)    SAVETONER="-t";;
  221.     z)    MODEL="$OPTARG";;
  222.     l)    CLIP_LR="-l $OPTARG";;
  223.     u)    CLIP_UL="-u $OPTARG";;
  224.     L)    CLIP_LOG="-L $OPTARG";;
  225.     A)    AIB=-A;;
  226.     B)    BC=-B;;
  227.     C)    COLORMODE="$OPTARG";;
  228.     S)    COLOR2MONO="-S$OPTARG";;
  229.     D)    DEBUG="$OPTARG";;
  230.     G)    GAMMAFILE="$OPTARG";;
  231.     I)    INTENT="$OPTARG";;
  232.     P)    NOPLANES=-P;;
  233.     X)    EXTRAPAD="-X $OPTARG";;
  234.     [234689])    NUP="$opt";;
  235.     [57])    error "Can't find acceptable layout for $opt-up";;
  236.     1)    case "$OPTARG" in
  237.         [024568])    NUP="1$OPTARG";;
  238.         *)    error "Can't find acceptable layout for 1$OPTARG-up";;
  239.         esac
  240.         ;;
  241.     o)    case "$OPTARG" in
  242.         l*)    NUP_ORIENT=-l;;
  243.         s*)    NUP_ORIENT=-r;;
  244.         p*|*)    NUP_ORIENT=;;
  245.         esac;;
  246.     V)    echo "$VERSION"; foo2qpdl -V; foo2zjs-pstops -V; exit 0;;
  247.     h|\?)
  248.         if [ "$CMDLINE" != "-?" -a "$CMDLINE" != -h ]; then
  249.             echo "Illegal command:"
  250.             echo "    $0 $CMDLINE"
  251.             echo
  252.         fi
  253.         usage;;
  254.     esac
  255. done
  256. shift `expr $OPTIND - 1`
  257.  
  258. #
  259. # If there is an argument left, take it as the file to print.
  260. # Else, the input comes from stdin.
  261. #
  262. if [ $# -ge 1 ]; then
  263.     if [ "$LPJOB" = "" ]; then
  264.     : # LPJOB="$1"
  265.     fi
  266.     exec < $1
  267. fi
  268.  
  269. #
  270. case "$QUALITY" in
  271. 0)
  272.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  273.     ;;
  274. 1)
  275.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  276.     ;;
  277. 2)
  278.     GSOPTS="-dMaxBitmap=500000000 $GSOPTS"
  279.     ;;
  280. wts)
  281.     GSOPTS="-dCOLORSCREEN -dMaxBitmap=500000000 $GSOPTS"
  282.     ;;
  283. esac
  284.  
  285. #
  286. #    Validate model code
  287. #
  288. case "$MODEL" in
  289. 0|1|2)    ;;
  290. *)    error "Unknown model code $MODEL";;
  291. esac
  292.  
  293. #
  294. #    Validate media code
  295. #
  296. case "$MEDIA" in
  297. 0|plain)    MEDIA=0;;
  298. 1|thick)    MEDIA=1;;
  299. 2|thin)        MEDIA=2;;
  300. 3|bond)        MEDIA=3;;
  301. 4|color)    MEDIA=4;;
  302. 5|card)        MEDIA=5;;
  303. 6|labels)    MEDIA=6;;
  304. 7|envelope)    MEDIA=7;;
  305. 8|preprinted)    MEDIA=8;;
  306. 9|cotton)    MEDIA=9;;
  307. 10|recycled)    MEDIA=10;;
  308. [0-9]*)        ;;
  309. *)        error "Unknown media code $MEDIA";;
  310. esac
  311.  
  312. #
  313. #    Validate source (InputSlot) code
  314. #
  315. case "$SOURCE" in
  316. 1|auto)        SOURCE=1;;
  317. 2|manual)    SOURCE=2;;
  318. 3|multi)    SOURCE=3;;
  319. 4|tray1)    SOURCE=4;;
  320. [0-9]*)        ;;
  321. *)        error "Unknown source code $SOURCE";;
  322. esac
  323.  
  324. #
  325. #    Validate Duplex code
  326. #
  327. case "$DUPLEX" in
  328. 1|off|none)    DUPLEX=1;;
  329. 2|long*)    DUPLEX=2;;
  330. 3|short*)    DUPLEX=3;;
  331. [0-9]*)        ;;
  332. *)        error "Unknown duplex code $DUPLEX";;
  333. esac
  334.  
  335. #
  336. #    Validate Resolution
  337. #
  338. case "$RES" in
  339. 600x600)    ;;
  340. 1200x600)    ;;
  341. 1200x1200)    ;;
  342. *)        error "Illegal resolution $RES";;
  343. esac
  344.  
  345. #
  346. #    Figure out the paper dimensions in pixels/inch, and set the
  347. #    default clipping region.  Unfortunately, this is a trouble
  348. #    area for ZjStream printers.  Various versions of ZjS print
  349. #    engines react differently when asked to print into their
  350. #    unprintable regions.
  351. #
  352. set_clipping() {
  353.     ulx=$1; uly=$2
  354.     lrx=$3; lry=$4
  355.  
  356.     # Set clipping region if it isn't already set
  357.     if [ "$CLIP_UL" = "" ]; then
  358.     case "$RES" in
  359.     600x600)    ulx=`expr $ulx / 2`;;
  360.     2400x600)    ulx=`expr $ulx \* 2`;;
  361.     esac
  362.     CLIP_UL="-u ${ulx}x${uly}"
  363.     fi
  364.     if [ "$CLIP_LR" = "" ]; then
  365.     case "$RES" in
  366.     600x600)    lrx=`expr $lrx / 2`;;
  367.     2400x600)    lrx=`expr $lrx \* 2`;;
  368.     esac
  369.     CLIP_LR="-l ${lrx}x${lry}"
  370.     fi
  371. }
  372.  
  373. case "$PAPER" in
  374. Custom*)
  375.         case "$PAPER" in
  376.         Custom\.[0-9]*\x[0-9]*)
  377.             XDIM=`echo "$PAPER" | sed -e 's/Custom\.//' -e 's/x.*//'`
  378.             YDIM=`echo "$PAPER" | sed -e 's/Custom\.//' -e 's/.*x//'`
  379.             ;;
  380.         *)
  381.         #%%BeginFeature: *CustomPageSize True
  382.         #216
  383.         #360
  384.         #0
  385.         #0
  386.         #0
  387.         #pop pop pop pop pop
  388.  
  389.         #%%BeginFeature: *CustomPageSize True
  390.         #792.000000 612.000000 1 0.000000 0.000000
  391.         #pop pop pop pop pop
  392.  
  393.         if [ $DEBUG = 0 ]; then
  394.             TMPFILE=/tmp/cus$$
  395.         else
  396.             TMPFILE=/tmp/custom.ps
  397.         fi
  398.         cat >$TMPFILE
  399.         exec <$TMPFILE
  400.  
  401.         tmp=`head -n 10000 $TMPFILE \
  402.             | sed -n '/CustomPageSize/{n;p;n;p;}' \
  403.             | tr '\n' ' '`
  404.         case "$tmp" in
  405.         [0-9]*\ [0-9]*)
  406.             XDIM=`echo "$tmp" | sed 's/ .*//'`
  407.             YDIM=`echo "$tmp" | sed -e 's/^[^ ]* //' -e 's/ .*//'`
  408.             ;;
  409.         *)
  410.             if [ $DEBUG = 0 ]; then rm -f $TMPFILE; fi
  411.             error "Custom page size [XY]DIM != 1-99999"
  412.             ;;
  413.         esac
  414.         ;;
  415.         esac
  416.         XDIM=`dc -e "$XDIM 1200* 72/p"`
  417.         YDIM=`dc -e "$YDIM 600* 72/p"`
  418.         PAPER=21;        paper=letter;
  419.         # Doesn't work on a real printer - smudges.
  420.                 # set_clipping 2 100     2 100
  421.         set_clipping 150 100    150 100
  422.         ;;
  423. 0|letter)    PAPER=0;    paper=letter;    XDIM="10200"; YDIM="6600"
  424.         set_clipping 150 100    150 100
  425.         ;;
  426. 1|legal)    PAPER=1;    paper=legal;     XDIM="10200"; YDIM="8400"
  427.         set_clipping 150 100    150 100
  428.         ;;
  429. 3|executive)    PAPER=3;    paper=executive; XDIM="8700";  YDIM="6300"
  430.         set_clipping 150 100    150 100
  431.         ;;
  432. 2|a4|A4)    PAPER=2;    paper=a4;        XDIM="9920";  YDIM="7016"
  433.         set_clipping 150 100    150 100
  434.         ;;
  435. 16|a5|A5)    PAPER=16;    paper=a5;        XDIM="6992";  YDIM="4960"
  436.         set_clipping 150 100    150 100
  437.         ;;
  438. 11|b5jis|B5jis)    PAPER=11;    paper=b5;        XDIM="8598";  YDIM="6070"
  439.         set_clipping 150 100    150 100
  440.         ;;
  441. 24|folio)    PAPER=24;    paper=folio;     XDIM="9922"; YDIM="7796"
  442.         set_clipping 150 100    150 100
  443.         ;;
  444. 26|"env#9")    PAPER=26;    paper=env9;      XDIM="4496";  YDIM="5324"
  445.         set_clipping 150 100    150 100
  446.         ;;
  447. 6|"env#10")    PAPER=6;    paper=env10;     XDIM="4950";  YDIM="5700"
  448.         set_clipping 150 100    150 100
  449.         ;;
  450. 9|envDL)    PAPER=9;    paper=envDL;     XDIM="5200";  YDIM="5200"
  451.         set_clipping 150 100    150 100
  452.         ;;
  453. 8|envC5)    PAPER=8;    paper=envC5;     XDIM="7650";  YDIM="5408"
  454.         set_clipping 150 100    150 100
  455.         ;;
  456. 23|envC6)    PAPER=23;    paper=envC6;     XDIM="5386";  YDIM="3826"
  457.         set_clipping 150 100    150 100
  458.         ;;
  459. 12|b5iso|B5iso)    PAPER=12;    paper=b5;        XDIM="8314";  YDIM="5906"
  460.         set_clipping 150 100    150 100
  461.         ;;
  462. 7|envMonarch)    PAPER=7;    paper=envMonarch;XDIM="4650";  YDIM="4500"
  463.         set_clipping 150 100    150 100
  464.         ;;
  465. 25|env6.75)    PAPER=25;    paper=env6.75;   XDIM="4348";  YDIM="3900"
  466.         set_clipping 150 100    150 100
  467.         ;;
  468. 17|a6|A6)    PAPER=17;    paper=a6;        XDIM="4960";  YDIM="3496"
  469.         set_clipping 150 100    150 100
  470.         ;;
  471. 28|oficio)    PAPER=28;    paper=a6;        XDIM="10200"; YDIM="8100"
  472.         set_clipping 150 100    150 100
  473.         ;;
  474. *)        error "Unimplemented paper code $PAPER";;
  475. esac
  476. # e.g. /usr/share/ghostscript/7.07/lib/gs_statd.ps
  477. PAPERSIZE="-sPAPERSIZE=$paper";
  478.  
  479. case "$RES" in
  480. 600x600)    XDIM=`expr $XDIM / 2`;;
  481. 1200x600)    ;;
  482. 1200x1200)    YDIM=`expr $YDIM \* 2`;;
  483. esac
  484. DIM="${XDIM}x${YDIM}"
  485.  
  486. #
  487. # Filter thru psnup if N-up printing has been requested
  488. #
  489. case $NUP in
  490. [234689]|1[024568])    PREFILTER="nup";;
  491. *)            PREFILTER=cat;;
  492. esac
  493. if [ "$DEBUG" -ge 9 ]; then
  494.     PREFILTER="tee /tmp/$BASENAME.ps"
  495. fi
  496.  
  497. #
  498. #    Overload -G.  If the file name ends with ".icm" or ".ICM"
  499. #    then convert the ICC color profile to a Postscript CRD,
  500. #    then prepend it to the users job.  Select the intent
  501. #    using the -I option.
  502. #
  503.  
  504. create_crd() {
  505.     #
  506.     # Create a Postscript CRD
  507.     #
  508.     ICC2PS=$PREFIX/bin/foo2zjs-icc2ps
  509.     if [ -x $ICC2PS ]; then
  510.     case "$GAMMAFILE" in
  511.     none | none.icm | */none.icm)
  512.         ;;
  513.     *)
  514.         $ICC2PS -o $GAMMAFILE -t$INTENT > $ICCTMP.crd.ps 2>$ICCTMP.log \
  515.         || error "Problem converting .ICM file to Postscript"
  516.         ;;
  517.     esac
  518.  
  519.     PSTOPS_OPTS="$PSTOPS_OPTS -c"
  520.     cat > $ICCTMP.usecie.ps <<-EOF
  521.         %!PS-Adobe-3.0
  522.         <</UseCIEColor true>>setpagedevice
  523.     EOF
  524.     if [ "$QUALITY" = wts ]; then
  525.         cat >> $ICCTMP.usecie.ps <<-EOF
  526.         << /UseWTS true >> setuserparams
  527.         <<
  528.             /AccurateScreens true
  529.             /HalftoneType 1
  530.             /HalftoneName (Round Dot Screen) cvn
  531.             /SpotFunction { 180 mul cos exch 180 mul cos add 2 div}
  532.             /Frequency 137
  533.             /Angle 37
  534.         >> sethalftone
  535.         EOF
  536.     fi
  537.     cat > $ICCTMP.selcrd.ps <<-EOF
  538.         /Current /ColorRendering findresource setcolorrendering
  539.     EOF
  540.     case "$GAMMAFILE" in
  541.     none | none.icm | */none.icm) GAMMAFILE="$ICCTMP.usecie.ps";;
  542.     *)    GAMMAFILE="$ICCTMP.usecie.ps $ICCTMP.crd.ps $ICCTMP.selcrd.ps";;
  543.     esac
  544.     else
  545.     GAMMFILE=
  546.     fi
  547. }
  548.  
  549. if [ $DEBUG -gt 0 ]; then
  550.     ICCTMP=/tmp/icc
  551. else
  552.     ICCTMP=/tmp/icc$$
  553. fi
  554.  
  555. if [ "" = "$COLOR" ]; then
  556.     COLORMODE=
  557.     GAMMAFILE=
  558. else
  559.     case "$COLORMODE" in
  560.     default)    COLORMODE=$DEFAULTCOLORMODE;;
  561.     esac
  562.     case "$GAMMAFILE" in
  563.     default)    GAMMAFILE=samclp300-0.icm;;
  564.     esac
  565. fi
  566.  
  567. CRDBASE="$PREFIX/share/foo2qpdl/crd"
  568. case "$MODEL" in
  569.     0)    model=CLP-300;;
  570.     1)    model=CLP-600;;
  571.     2)    model=CLP-600;;
  572. esac
  573. case "$RES" in
  574.     600x600)    SCREEN=$model-600x600cms2;;
  575.     1200x600)    SCREEN=$model-1200x600cms2;;
  576.     1200x1200)    SCREEN=$model-1200x1200cms2;;
  577. esac
  578.  
  579. PSTOPS_OPTS="-n"
  580.  
  581. case "$COLORMODE" in
  582. 0|"")
  583.     # Monochrome
  584.     ;;
  585. 10|icm)
  586.     # Use old ICM method
  587.     AIB=-A
  588.     BC=-B
  589.     case "$GAMMAFILE" in
  590.     none | none.icm | */none.icm)
  591.     create_crd
  592.     ;;
  593.     *.icm|*.ICM|*.icc|*.ICC)
  594.     #
  595.     # Its really an .ICM file, not a gamma file.
  596.     #
  597.     # The file can be a full path name, or the name of a file in $SHARE/icm/
  598.     #
  599.     if [ -r "$GAMMAFILE" ]; then
  600.         create_crd
  601.     elif [ -r "$SHARE/icm/$GAMMAFILE" ]; then
  602.         GAMMAFILE="$SHARE/icm/$GAMMAFILE"
  603.         create_crd
  604.     else
  605.         GAMMAFILE=
  606.     fi
  607.     ;;
  608.     esac
  609.     ;;
  610. 1|crd)
  611.     # CRD
  612.     GAMMAFILE=""
  613.     GAMMAFILE="$GAMMAFILE $CRDBASE/${model}cms"
  614.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  615.     # Black text...
  616.     TMPFILE2=/tmp/black$$
  617.     cat $CRDBASE/black-text.ps - >$TMPFILE2
  618.     exec <$TMPFILE2
  619.     ;;
  620. *.crd)
  621.     GAMMAFILE="$CRDBASE/prolog.ps"
  622.     if [ -f $COLORMODE ]; then
  623.     GAMMAFILE="$GAMMAFILE $COLORMODE"
  624.     elif [ -f $CRDBASE/$COLORMODE ]; then
  625.     GAMMAFILE="$GAMMAFILE $CRDBASE/$COLORMODE"
  626.     else
  627.     error "Can't find CRD '$COLORMODE' in . or in $CRDBASE"
  628.     fi
  629.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  630.     ;;
  631. *)
  632.     error "Unknown color method '$COLORMODE'"
  633.     ;;
  634. esac
  635.  
  636. if [ "$COLOR" != "" -a "$QUALITY" = wts ]; then
  637.     PSTOPS_OPTS="$PSTOPS_OPTS -w"
  638. fi
  639.  
  640. if [ "" != "$COLOR" ]; then
  641.     if [ "" = "$AIB" -a "" = "$BC" ]; then
  642.     # Faster, but can't handle AllIsBlack or BlackClears
  643.     GSDEV=-sDEVICE=pksmraw
  644.     else
  645.     # Can't handle different size pages
  646.     GSDEV=-sDEVICE=bitcmyk
  647.     fi
  648. fi
  649.  
  650. #
  651. #    Figure out USERNAME
  652. #
  653. if [ "$LPUSER" != "" ]; then
  654.     USER="$LPUSER@$LPHOST"
  655. else
  656.     USER=""
  657. fi
  658.  
  659. #
  660. #    Main Program, just cobble together the pipeline and run it
  661. #
  662. #    The malarky with file descriptors 1 and 3 is to avoid a bug in
  663. #    (some versions?) of Ghostscript where Postscript's stdout gets
  664. #    intermingled with the printer drivers output, resulting in
  665. #    corrupted image data.
  666. #
  667. GS="$GSBIN -q -dBATCH -dSAFER -dQUIET -dNOPAUSE"
  668.  
  669. foo2zjs-pstops $PSTOPS_OPTS | \
  670. $PREFILTER \
  671. | ($GS $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS \
  672.     -sOutputFile="|cat 1>&3" $GAMMAFILE -_ >/dev/null) 3>&1 \
  673. | foo2qpdl -r$RES -g$DIM -p$PAPER -m$MEDIA -n$COPIES -d$DUPLEX -s$SOURCE \
  674.         -z$MODEL $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG $SAVETONER \
  675.         -J "$LPJOB" -U "$USER" \
  676.         $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD -D$DEBUG
  677.  
  678. #
  679. #    Log the command line, for debugging and problem reports
  680. #
  681. if [ -x /usr/bin/logger ]; then
  682.     logger -t "$BASENAME" -p lpr.info -- \
  683.     "$GSBIN $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS $GAMMAFILE"
  684.     logger -t "$BASENAME" -p lpr.info -- \
  685.     "foo2qpdl -r$RES -g$DIM -p$PAPER -m$MEDIA \
  686. -n$COPIES -d$DUPLEX -s$SOURCE -z$MODEL $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG \
  687. $SAVETONER $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD"
  688. fi
  689.  
  690. #
  691. #    Remove cruft
  692. #
  693. if [ $DEBUG -eq 0 ]; then
  694.     for i in crd.ps log usecie.ps selcrd.ps
  695.     do
  696.     file="$ICCTMP.$i"
  697.     [ -f $file ] && rm -f $file
  698.     done
  699.     [ -f "$TMPFILE" ] && rm -f $TMPFILE
  700.     [ -f "$TMPFILE2" ] && rm -f $TMPFILE2
  701. fi
  702.  
  703. exit 0
  704.